package youcaihuaoa.weetop.com.ui.adapter

import android.text.Editable
import android.text.InputType
import android.text.TextWatcher
import androidx.appcompat.widget.AppCompatEditText
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.MyApplyInfoBean
import youcaihuaoa.weetop.com.R

class MyApplyInfoAdapter :
    BaseQuickAdapter<MyApplyInfoBean, BaseViewHolder>(R.layout.app_item_my_apply_profile) {
    override fun convert(holder: BaseViewHolder, item: MyApplyInfoBean) {
        holder.setGone(R.id.item_tv_value, item.type == "0")
            .setGone(R.id.item_edit_content, item.type != "0")
            .setText(R.id.item_tv_title, item.title)
            .setEnabled(R.id.item_edit_content, item.type != "0" || item.enable)
            .setImageResource(
                R.id.item_iv_icon, if (item.type == "0") {
                    R.mipmap.app_ic_menu_edit
                } else {
                    R.mipmap.app_ic_menu_date
                }
            )
            .setGone(R.id.item_v_line, holder.adapterPosition == data.size - 1)
            .setVisible(R.id.item_tv_xing, !item.title.contains("备注"))

        if (item.type == "0") {
            holder.setText(R.id.item_edit_content, item.text)

            val editContent = holder.getView<AppCompatEditText>(R.id.item_edit_content)
            editContent.inputType = if (item.inputType == 0) {
                InputType.TYPE_CLASS_TEXT
            }else{
                InputType.TYPE_CLASS_NUMBER
            }
        } else {
            holder.setText(R.id.item_tv_value, item.text)
        }
        holder.itemView.isEnabled = item.enable

        holder.getView<AppCompatEditText>(R.id.item_edit_content)
            .addTextChangedListener(object : TextWatcher {
                override fun beforeTextChanged(
                    s: CharSequence?,
                    start: Int,
                    count: Int,
                    after: Int
                ) {

                }

                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                    item.text = s.toString()
                }

                override fun afterTextChanged(s: Editable?) {

                }
            })
    }
}